# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Josef Fröhle <github@josef-froehle.de>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libspf2
pkgver=1.2.11
_commit=8131fe140704eaae695e76b5cd09e39bd1dd220b
pkgrel=3
pkgdesc="Sender Policy Framework library, a part of the SPF/SRS protocol pair."
url="https://www.libspf2.org/"
arch="all"
license="LGPL-2.1-or-later OR BSD-2-Clause"
subpackages="$pkgname-dev $pkgname-tools"
makedepends="autoconf automake libtool"
options="!check" # no test suite
source="$pkgname-$pkgver.tar.gz::https://github.com/shevek/libspf2/archive/$_commit.tar.gz
	CVE-2023-42118.patch
	00001.patch
	00002.patch
	netdb_success.patch
	musl-res_close.patch
	implicit.patch
	"
builddir="$srcdir/$pkgname-$_commit"

# secfixes:
#   1.2.11-r3:
#     - CVE-2023-42118
#   1.2.11-r0:
#     - CVE-2021-33912
#     - CVE-2021-33913
#     - CVE-2021-33914
#   1.2.10-r5:
#     - CVE-2021-20314

prepare() {
	default_prepare
	update_config_sub
	rm -r src/libreplace

	libtoolize --force && aclocal && automake --add-missing && autoconf \
		&& autoheader
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

tools() {
	pkgdesc="SPF daemon and command-line utility"
	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/usr/sbin
	mv "$pkgdir"/usr/bin/spfquery "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/spfd "$subpkgdir"/usr/sbin
	rm -fr "$pkgdir"/usr/bin
}

sha512sums="
bbc8b053aa5dc960be7a31ee4d4385d9ed7f42a7c998a392626610de9a7dd9f95f16ad309990d0118f1eab3bed49189ed1be9c30d291c0ca54541677a968ceb3  libspf2-1.2.11.tar.gz
9e17764f24de8147a27a41a5aeaf0554af6f434c04aa5ddea56fd4692f208c1c2576acd28ff06a2be6ff32945f5a441405b2ebb2f393c6a571e34723b023b1f5  CVE-2023-42118.patch
3b9bff9b5a5b95f6722f86a43373b0c84cbb79a4509cf0c73486612c0a1b33587bb0b42966b0d2e3a317e4d7a730091fa444bd1258afd06bb3553c4a96d3ee34  00001.patch
18ddfe106b652e2fb9e36a9f1743fc7cecf38530da65a06ac892b60d2c430aaad657f5653495950d4af4b9833826366b79e629937498e5ce7f6af716303221c4  00002.patch
033dd1e959004f7a1026fb1de73813e934560101e04897297e468918ee28e4d7d0f271d6f05d984db22dd43e097f6aa133df18d11419b085d89db89b120750c9  netdb_success.patch
4fb8a28a667d8fe54a48fa89230446b758c6d532866ee26e8b9ef3032f6e0993ec19a2cc2fb265d18d259e35de6fe66183763bbc69c424de70ad8fe0dbcf7a2f  musl-res_close.patch
1c17b099e8a3533c45881250a62c8bc52bd46572a7a36588ea9063dca09f7d431d870289abafe15ec5285354fb14301a4b6c866dd6ccd8da4488dd73cbdd7af2  implicit.patch
"
